const express = require('express')
const router = express.Router()
const Users = require('../models/users')

//查询所有用户信息
// router.get('/users',(req,res) => {
// 	Users.find({})
// })

//用户登录
router.post('/query',(req,res) => {
	const username = req.body.username
	const password = req.body.password
	const obj = {}
	
	if(username != ''){
		obj['username'] = username
	}
	if(password != ''){
		obj['password'] = password
	}
	Users.find(obj, (err, docs) => {
		if (err) {
		  res.send({ 'code': 1, 'errorMsg': '查询失败' });
		} else {
		  res.send(docs);
		}
	})
})


module.exports = router;

